package com.hamster.crmpre.web;

import com.hamster.crmpre.config.LoginInterceptor;
import com.hamster.crmpre.pojo.Customer;
import com.hamster.crmpre.service.CustomerQueryService;
import com.hamster.crmpre.service.DepartmentIdQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ：Lizhipeng
 * @date ：Created in 2019/12/25 12:49
 * @description：客户信息查询控制器
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("customerQuery")
public class CustomerQueryController {

    @Autowired
    private CustomerQueryService customerQueryService;
    @Autowired
    private DepartmentIdQueryService departmentIdQueryService;

    /**
     * 根据department获取客户信息列表
     * @return List<Employee> 客户信息列表
     */
    @GetMapping("list")
    public ResponseEntity<List<Customer>> list(){
        String department = LoginInterceptor.getLoginUser().getDepartment();
        String departmentId = department.split(",")[0];
        List<Customer> customersList = customerQueryService.list(departmentId);
        //System.out.println(customersList);
        return ResponseEntity.ok(customersList);
    }


    /**
     * 获取个人负责的客户的列表
     * @return
     */
    @GetMapping("listCustomerPersonal")
    public ResponseEntity<List<Customer>> listCustomerPersonal(@RequestParam(required = false) String name){
        List<Customer> list = customerQueryService.listCustomerPersonal(name);
        return ResponseEntity.ok(list);
    }

    /**
     * 获取个人负责的VIP的列表
     * @return
     */
    @GetMapping("listCustomerPersonalVip")
    public ResponseEntity<List<Customer>> listCustomerPersonalVip(@RequestParam(required = false) String name){
        List<Customer> list = customerQueryService.listCustomerPersonalVip(name);
        return ResponseEntity.ok(list);
    }

    /**
     * 事业部获取手下分公司开发的客户的列表
     * @return
     */
    @GetMapping("companyListCustomerPersonal")
    public ResponseEntity<List<Customer>> companyListCustomerPersonal(@RequestParam String companyId, @RequestParam(required = false) String name){
        List<Customer> list = customerQueryService.companyListCustomerPersonal(companyId,name);
        return ResponseEntity.ok(list);
    }

    /**
     * 事業部 查詢分公司列表
     * @param name
     * @return
     */
    @GetMapping("getCompanyList")
    public ResponseEntity<List<Map<String,Object>>> getCompanyList(@RequestParam(required = false) String name){
        String userId = LoginInterceptor.getLoginUser().getUserId();
        List<Map<String,Object>> list = customerQueryService.getCompanyList(userId,name);
        return ResponseEntity.ok(list);
    }


}
